<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
    String contextPath = (String) request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" href="<%=contextPath%>/css/reset.css"
	rel="stylesheet" />
<link rel="stylesheet" href="<%=contextPath%>/css/style.css"
	type="text/css" />
<link rel="stylesheet" href="<%=contextPath%>/css/home.css"
	type="text/css" />
<link rel="stylesheet" type="text/css"
	href="<%=contextPath%>/js/jquery-easyui-1.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="<%=contextPath%>/css/rs.css">
<link rel="stylesheet" type="text/css"
	href="<%=contextPath%>/js/jquery-easyui-1.3/themes/icon.css">
<link href="<%=contextPath%>/js/uploadify/uploadify.css"
	rel="stylesheet" type="text/css" />
<script type="text/javascript"
	src="<%=contextPath%>/js/jquery-easyui-1.3/jquery-1.7.2.min.js"></script>
<script type="text/javascript"
	src="<%=contextPath%>/js/jquery-easyui-1.3/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="<%=contextPath%>/js/jquery-easyui-1.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript"
	src="<%=contextPath%>/js/uploadify/jquery.uploadify.min.js"></script>
<script>
	var selectedIds = "";
	$(document).ready(function(){
		$('#wndAdd').window({closed:true});//  data-options="closed:true"
		$('#wndSearch').window({closed:true});
		$('#wndBatchImp').window({closed:true});
		$('#wndDetail').window({closed:true});
	});
 

	$(function() {
		$('#dataTable').datagrid({
			title : '预约挂号',
			height : 500,
			nowrap : true,
			autoRowHeight : false,
			striped : true,
			collapsible : false,
			url : '<%=contextPath%>/admin/doctorAction.do?method=doctorList4Admin',
			sortName : 'id',
			sortOrder : 'desc',
			remoteSort : false,
			idField : 'id',
			singleSelect :true,
			checkOnSelect:false,
			selectOnCheck:true,
			onCheck:function(rowIndex,rowData){
				selectedIds+=rowData.id+",";
			},
			onSelectAll:function(rows){
				for(var i=0;i<rows.length;i++){
					selectedIds+=rows[i].id+",";
				}
			},
			onUncheckAll:function(rows){
				selectedIds='';
			},
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				title : 'ID',
				field : 'id',
				width : 30,
				sortable : true
			}, 
			{
				field : 'name',
				title : '姓名',
				width : 100,
				sortable : true
			}, 
			{
				field : 'gender',
				title : '性别',
				width : 50,
				formatter:function(value,row,index){
					if(value=='m') return "男";
					if(value=='f') return "女";
					return '';
				}
			}, 
			{
				field : 'pro_title',
				title : '专业职称',
				width : 100,
				formatter:function(value,row,index){
					return row.pro_title_cn;
				}
			}, 
			{
				field : 'hos_name',
				title : '医院',
				width : 200,
				sortable : true
			}, 
			{
				field : 'parent_cat_name',
				title : '科室',
				width : 150,
				sortable : true,
				formatter:function(value,row,index){
				return row.parent_cat_name + " - " + row.child_cat_name;
				}
			}, 
			{
				field : 'sc_date',
				title : '排班日期',
				width : 150,
				sortable : true,
				formatter:function(value,row,index){
				var str = row.sc_date_str + " " + row.batch_str;
				return str;
				}
			}, 
			{
				field : 'self_code',
				title : '医院内部编号',
				width : 80,
				sortable : true
			}, 
			
			{
				field : 'opt',
				title : '操作',
				width : 100,
				align : 'center',
				rowspan : 2,
				formatter : function(value, row,index) {
					return '<a style="color:red" href="#" mce_href="#" onClick="editSingle('+row.id+')">预约</a>';
				},hidden : true
			} ] ],

			pagination : true,
			rownumbers : true,
			
			toolbar : [ {
				id : 'btnadd',
				text : '新增',
				url:'',
				iconCls : 'icon-add',
				handler : function() {
					$("#addForm").form('clear');
					$('#wndAdd').window({
						closed:false,
						title:"新增订单",
						width : 800,
						height :450,
						top:($(window).height()-450)*0.5,   
			            left:($(window).width()-800)*0.5,
						modal : true,
						onload:function(){
						//$("")	
						}
					});
				}
			},{
				id : 'btnedit',
				text : '预约',
				iconCls : 'icon-edit',
				handler : function() {
					var rows = $('#dataTable').datagrid('getSelections'); 
					//判断是否选择行
					if (!rows || rows.length == 0) { 
						$.messager.alert('提示', '请选择记录开始预约!', 'info'); 
						return; 
					} else {
						if (rows.length == 1) {
							editSingle(rows[0].id);
						} else if (rows.length>1) {
							$.messager.alert('提示', '请选择一条记录开始预约!', 'info'); 
							return;
						}
				    }
				}
			},{
				id : 'btnsearch',
				text : '条件查询',
				iconCls : 'icon-search',
				handler : function() {
					$("#searchForm").form('clear');
					$('#wndSearch').window({
						title:"查询",
						closed:false,
						width : 950,
						height : 180,
						top:($(window).height()-180)*0.5,   
			            left:($(window).width()-950)*0.5,
						modal : true
					});
				}
			}]
		});
		
		
		var p = $('#dataTable').datagrid('getPager');
		$(p).pagination({
			onBeforeRefresh : function() {
				//alert('before refresh');
			}
		});
		
		//查询
		$("#btSch").click(function(){
			var v_hospital_id = $("#sch_hospital_id").combobox('getValue');
			var v_parent_cat = $("#sch_parent_cat").combobox('getValue');
			var v_child_cat = $("#sch_child_cat").combobox('getValue');
			var v_pro_title = $("#sch_pro_title").combobox('getValue');
			var v_self_code = $("#sch_self_code").val();
			var v_status = $("#sch_status").combobox('getValue');
			var v_name = $("#sch_name").val();
			$('#dataTable').datagrid('reload',{
				hospital_id:v_hospital_id,
				parent_cat: v_parent_cat,
				child_cat: v_child_cat,
				pro_title:v_pro_title,
				self_code:v_self_code,
				status:v_status,
				name:v_name
				//city_code:v_city_code
			});
		});
		
		//清除
		$("#bt_clear").click(function(){
			$("#searchForm").form('clear');
		});
		$(function () { 
	        var options = { 
	            required: "true", 
	            missingMessage: "必填项", 
	            formatter: function (date) { 
	                var y = date.getFullYear(); 
	                var m = date.getMonth() + 1; 
	                var d = date.getDate(); 
	                return y + "-" + (m < 10 ? ("0" + m) : m) + "-" + (d < 10 ? ("0" + d) : d) ; 
	            } 
	        } 
	        $("#sch_sc_date").datebox(options); 
	        $("#e_sc_date").datebox(options);
	    }); 

		
		//保存
		$("#bt_submit").click(function(){
			$("#addForm").form('submit',{
				url:'<%=contextPath%>/source/sourceMgrAction.do?method=save',
				onSubmit:function(){
					return $("#addForm").form('validate');
					//return true;
				},		
				success:function(data){
					var data = eval('(' + data + ')');  
					$.messager.alert('提示',data.msg);
					if(data.flag=='success'){
					$("#addForm").form('clear');
					$('#wndAdd').window('close');
					$('#dataTable').datagrid('reload');
					}
				}
			});
		});
		
		
			//新增编辑页面校验
			$("#e_name").validatebox({
				required:true
			});
			$("#hospital_id").validatebox({
				required:true
			});
			$("#e_gender").validatebox({
				required:true
			});
			$("#e_self_code").validatebox({
				required:true
			});
			
			/*
			$("#section_id").validatebox({
				required:true
			});
			$("#e_pro_title").validatebox({
				required:true
			});*/
			
			
		
		$("#bt_close").click(function(){
			$('#wndAdd').window('close');
		});
		
		
		//load 医院列表
		$("#hospital_id").combobox({
			url:'<%=contextPath%>/admin/doctorAction.do?method=initHospital',
			editable:false,
			valueField:'id',
			textField:'name',	
			onSelect:function(rec){
				var url = '<%=contextPath%>/admin/doctorAction.do?method=initSecList&hospital_id='+rec.id;
				$('#section_id').combobox({
					url:url,
					valueField:'id',
					textField:'name',
					editable:false,
					onLoadSuccess:function(){
						var hidSecid = $("#hid_section_id").val();
						if(hidSecid!=''&&hidSecid!='0'){
							$('#section_id').combobox('setValue',hidSecid);
						}
					}
				});
			}
		});
		// 搜索框中的下拉菜单
		$("#sch_parent_cat").combobox({
			url:'<%=contextPath %>/admin/secCatalogAction.do?method=getParentCatalogs',
			valueField:'id',
			textField:'name',
			onSelect:function(rec)
			{
				var childUrl = '<%=contextPath %>/admin/secCatalogAction.do?method=getCatalogOfParent&id='+rec.id;
				
				$("#sch_child_cat").combobox({
					url: childUrl,
					valueField:'id',
					textField:'name',
					onSelect:function(rec2){
						var childName = rec2.name;
						$("#name").val(childName);
					}
				});
			}
		});

		// 新增窗口中的下拉菜单
		$("#parent_cat_id").combobox({
			url:'<%=contextPath %>/admin/secCatalogAction.do?method=getParentCatalogs',
			valueField:'id',
			textField:'name',
			onSelect:function(rec)
			{
				var childUrl = '<%=contextPath %>/admin/secCatalogAction.do?method=getCatalogOfParent&id='+rec.id;
				
				$("#child_cat_id").combobox({
					url: childUrl,
					valueField:'id',
					textField:'name',
					onSelect:function(rec2){
						var childName = rec2.name;
						$("#name").val(childName);
					},
					onLoadSuccess:function(){
						var child_cat_id = $("#hd_child_cat_id").val();
						if(child_cat_id!=''&&child_cat_id!='0'){
							$("#child_cat_id").combobox('setValue',child_cat_id);
						}
					}
				});
			},
			onLoadSuccess:function(){
				var hid_parent_id = $("#hd_parent_cat_id").val();
				if(hid_parent_id!=''&&hid_parent_id!='0'){
					$("#parent_cat_id").combobox('setValue',hid_parent_id);
				}
			}
		});
	});
	
	
	//查看详细
	function viewSingle(id){
		$('#wndDetail').window({
			title:"详情",
			closed:false,
			width : 700,
			height : 450,
			top:($(window).height()-450)*0.5,   
            left:($(window).width()-700)*0.5,
            loadingMessage:"加载中...",
			onOpen:function(){
				document.getElementById("frmDetail").src="<%=contextPath%>/admin/doctorAction.do?method=view&id="+id;
			},
			modal : true
		});
	}
	
	//编辑
	function editSingle(id){
		$("#addForm").form('clear');
		$.ajax({
			url:"<%=contextPath%>/admin/doctorAction.do?method=edit&id="+id+"&radom="+Math.random(),
			type:"post",
			success:function(data){
				var data = eval('('+data+')');
				$("#e_docname").val(data.name);
				$("#e_gender").combobox('select',data.gender);

				$("#hospital_id").combobox('select',data.hospitalId);
				$("#hospital_id").trigger('onSelect');
				
				$("#hd_parent_cat_id").val(data.catParentId);
				$("#parent_cat_id").combobox('setValue',data.parentCatId)
				// $("#parent_cat_id").trigger('change');
				var childUrl = '<%=contextPath %>/admin/secCatalogAction.do?method=getCatalogOfParent&id='+data.parentCatId;
				$("#hd_child_cat_id").val(data.childCatId);
				
				$("#child_cat_id").combobox({
					url: childUrl,
					valueField:'id',
					textField:'name',
					onSelect:function(rec2){
						var childName = rec2.name;
						$("#name").val(childName);
					}
				});
				
				var child_cat_id = $("#hd_child_cat_id").val();
				if(child_cat_id!=''){
					$("#child_cat_id").combobox('setValue',child_cat_id);
					 $("#hd_child_cat_id").val('');
				}
				
				
				$("#id").val(data.id);
				$("#e_self_code").val(data.selfCode);
				$("#e_education").val(data.education);
				$("#e_pro_title").combobox('select',data.proTitle);
				$("#e_experience").val(data.experience);
				$("#hid_image_id").val(data.image_id);
				if(data.path=='null'||data.path==''){
					$("#img_id").attr('src','<%=contextPath%>/img/no_photo.jpg');
					
				}else{
					
				$("#img_id").attr("src",'<%=contextPath%>/upload'+data.path);
				}
				$("#remark").val(data.remark);
				$("#intro").val(data.intro);
				$("#e_status").combobox('setValue',data.status);
			}
		});
		$('#wndAdd').window({
			title:"新增预约",
			closed:false,
			width : 700,
			height :450,
			top:($(window).height()-450)*0.5,   
            left:($(window).width()-700)*0.5,
			onload:function(){
			alert(xxxx);
			},
			modal : true
		});
	}
	
	//删除
	function deleteSingle(id){
		$.messager.confirm('删除','确定删除选择的医生吗?',function(r){
			if(r){
				$.ajax({
					url:"<%=contextPath%>/admin/doctorAction.do?method=delete&id="+id,
					type:"post",
					success:function(data){
					var data = eval('(' + data + ')');
					$.messager.alert('提示',data.msg);
					selectedIds = "";//多选时保存id  删除成功清空
					$('#dataTable').datagrid('reload');
					}
				});
			}
		});
	}
	
	function openDia (){$("#dialog").dialog({   //创建dialog弹窗  
        autoOpen:false,     //不自动打开窗口  
        show:"slide",       //显示弹窗出现的效果，slide为滑动效果  
        hide:"explode",     //显示窗口消失的效果，explode为爆炸效果  
        resizable:false,    //设置是否可拉动弹窗的大小，默认为true  
        modal:true,//是否有遮罩模型
        text:"xxxxx",
       buttons:[           //定义两个button按钮  
            {  
                text:"确定",  
                click:function(){  
                    $(this).dialog('close');    //关闭弹窗  
                    $("#label").append($("#e_docname").val());      //追加tr  
                        $(".del").click(function (){      
                            $(this).parent().parent().remove();         //点击删除按钮移除tr  
                            });  
                      
                    }     
            },  
           {  
                  
                text:"取消",  
                click:function(){  
                    $(this).dialog("close");    //点击取消，关闭弹窗  
                   }  
            }  
          
        ]  
    });  
      
   $("#bt_submit").button().click(function(){  
        $("#dialog").dialog("open");        //点击button按钮，显示弹窗  
     
        }); 
	}
</script>
<title>专家管理</title>
</head>
<body>
 <div id="wndSearch" class="easyui-window">
	<div class="easyui-panel admin_search" data-option="fit:true"
		style="margin: 2px 2px">
		<form id="searchForm">
			<table>
				<tr>
					<td class="textr" style="width:50px">
						医院：
					</td>
					<td style="width:160px">
						<input  id="sch_hospital_id"  name="sch_hospital_id" style="width:150px;"
							class="easyui-combobox" name="hospital_id"
							data-options="valueField:'id',textField:'name',url:'<%=contextPath%>/admin/doctorAction.do?method=initHospital'" />
					</td>
					<td class="textr" style="width:50px;">科室：</td>
					<td class="w180">
					<input class="easyui-combobox" id="sch_parent_cat" name="parent_cat" 
									 style="width:150px;" 
									 data-options="editable:false,valueField:'id',textField:'name',style:{width:150}" />
					<input id="sch_child_cat" class="easyui-combobox" name="sch_child_cat" 
									style="width:150px;" 
									data-options="editable:false,valueField:'id',textField:'name',style:{width:150}"/>
					</td>
			   </tr>
				<tr>	
					<td class="textr" sytle="width:50px">职称：</td>
					<td style="width:160px;">
						<input id="sch_pro_title" class="easyui-combobox"
							name="pro_title"
							data-options="valueField:'key',textField:'value',url:'<%=contextPath%>/admin/doctorAction.do?method=initProtitleList'" />
					</td>
					<td class="textr">医生姓名：</td>
					<td><input type="text" class="admin-input" id="sch_name"
						name="name"></td>
				</tr>
				<tr>		
					<td class="textr">医生状态：</td>
					<td><select class="easyui-combobox admin-select"
						id="sch_status" name="status"
						data-options="valueField:'id',textField:'text',data:[{id:'',text:'所有'},{id:'1',text:'有效'},{id:'0',text:'无效'}]">
					</select></td>
					
						<td class="textr w80">预约时间：</td>
						<td class=""><input id="sch_sc_date" name="sc_date" type="text" />
						
						</td>


					
				</tr>
			</table>
		</form>
		<div style="padding-left: 320px;">
			<input id="btSch" type="submit" name="submit" value=" 查 询"
				class="admin-btn">&nbsp;<input id="bt_clear" type="submit"
				name="submit" value=" 清除" class="admin-btn">
		</div>
	</div>
	</div>
	<div class="easyui-panel" data-option="fit:true"
		style="overflow: auto;">
		<table id="dataTable" class="easyui-datagrid">
		</table>
	</div>
	<div id="wndAdd" class="easyui-window">
		<div class="admin_search mAtuo"
			style="width: 520px; background-color: #fff;">

			<form id="addForm" method="post"
				action="<%=contextPath%>/source/sourceMgrAction.do?method=save">
				<input type="hidden" name="id" id="id" />
				<table>
					<tr>
						<td class="textr w80">患者姓名：</td>
						<td><input type="text" id="e_name" name="name"
							class="admin-input"></td>
						<td class="textr w80">性别：</td>
						<td class="w180"><select class="easyui-combobox admin-select"
							name="gender" id="e_gender"
							data-options="editable:false,valueField:'id',textField:'text',data:[{id:'m',text:'男',selected:true},{id:'f',text:'女'}]">
						</select></td>
					</tr>
					<tr>
						<td class="textr">身份证号：</td>
						<td><input type="text" id="e_idcard" name="id_card"
							class="admin-input"></td>
						<td class="textr">详细地址：</td>
						<td class="w180"><input type="text" id="e_addr" name="addr"
							class="admin-input"></td>
					</tr>
					<tr>
						<td class="textr w80">手机号码：</td>
						<td><input type="text" id="e_mobile" name="mobile_no"
							class="admin-input"></td>

					</tr>
					<tr>
						<td class="textr">所属医院：</td>
						<td class=""><select id="hospital_id"
							class="easyui-combobox" name="hospitalId">
						</select></td>
						<td class="textr">所属科室：</td>
						<td class="w180">
								<input class="easyui-combobox" id="parent_cat_id" name="parent_cat_id" 
									 style="width:150px;" 
									 data-options="editable:false,valueField:'id',textField:'name',style:{width:150}" />
								<br />
								<input id="hd_parent_cat_id" name="hd_parent_cat_id" type="hidden" />
								
							<input id="child_cat_id" class="easyui-combobox" name="child_cat_id" 
									style="width:150px;" 
									data-options="editable:false,valueField:'id',textField:'name',style:{width:150}"/>
							<input id="hd_child_cat_id" name="hd_child_cat_id" type="hidden" />
						</td>
					</tr>
					<tr>
						<td class="textr">医生姓名：</td>
						<td><input type="text" id="e_docname" name="docname"
							class="admin-input"></td>
						<td class="textr ">专业职称：</td>
						<td><input id="e_pro_title" class="easyui-combobox"
							name="proTitle"
							data-options="valueField:'key',textField:'value',url:'<%=contextPath%>/admin/doctorAction.do?method=initProtitleList'" />
						</td>

					</tr>
					<tr>
						<td class="textr ">预约日期：</td>
						<td class=""><input id="e_sc_date" name="sc_date" type="text" />

						<td class="textr w80">预约时段：</td>
						<td class=""><select id=e_batch_time name="batch">
  <option value ="1" selected="selected">上午</option>
  <option value ="2">下午</option>
  
</select>13987181159

					</tr>

				</table>
			</form>
			<div style="text-align: center;">
				
					<input type="submit" name="submit" value=" 确 认" class="admin-btn"
					id="bt_submit" onClick="javascript:openDia();">
					&nbsp;<input type="submit" name="submit"
					value=" 关 闭" class="admin-btn" id="bt_close">
			</div>
		</div>
	</div>

	<div id="wndBatchImp" class="easyui-window">
		<input type="file" id="file_imp" name="file_imp" />
		<p id="batch_step1"></p>
		<p id="batch_step2"></p>
		<p id="batch_step3"></p>
	</div>
	<div id="wndDetail" class="easyui-window">
		<iframe id="frmDetail" src="" width="100%" height="370px;"
			frameborder="0" scrolling="no" style="border: 0px none;"></iframe>
	</div>
	
</body>
</html>